package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class MinimumSubsequenceInNonIncreasingOrder {
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<Integer> minSubsequence(int[] nums) {
            final ArrayList<Integer> ans = new ArrayList<>();
            int total = Arrays.stream(nums).sum();
            Arrays.sort(nums);
            int cur = 0;
            for (int i = nums.length-1; i >=0; i--) {
                cur += nums[i];
                ans.add(nums[i]);
                if (total - cur < cur) {
                    break;
                }
            }
            return ans;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}